// pages/feedback/feedback.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    feedbackList:[],
    content: '',
    feedbackId: '',
    showCommentModal: false, // 控制弹框显示与隐藏  
    commentContent: '', 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    wx.request({
        url: app.rootUrl + '/getFeedbacks',
        data: {userId: app.accountInfo().accountId},
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        method: 'POST',
        success: function (res) {
          that.setData({
              feedbackList: res.data.rows
          });
        }
      })
  },
  handleInput: function(e) {  
    this.setData({  
      content: e.detail.value 
    });  
  },
  publishFeedback(){
    let that = this
    if(!that.data.content){
      wx.showToast({title: '请输入',
      icon: 'none',})
      return null
    }
    if(app.accountInfo() == null){
      wx.showToast({title: '请登陆',
      icon: 'none',})
      return null
    }
    wx.request({
        url: app.rootUrl + '/createFeedback',
        data: { 'userId': app.accountInfo().accountId, 'feedbackContent':that.data.content },
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        method: 'POST',
        success: function (res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
          })
          that.onShow()
          that.setData({  
            content: ''
          });  
        }
      })
  },
  delCommentFeedback(e){
    let that = this
    let feedbackid = e.currentTarget.dataset.feedbackid
    if(app.accountInfo() == null){
      wx.showToast({title: '请登陆',
      icon: 'none',})
      return null
    }
    wx.request({
        url: app.rootUrl + '/delFeedback',
        data: { 'feedbackId': feedbackid},
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        method: 'POST',
        success: function (res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
          })
          that.onShow()
        }
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})